using System;
using System.Collections.Generic;
using System.Text;

using IBatisNet.DataAccess.Configuration;
using IBatisNet.DataAccess;
using IBatisNet.Common.Utilities;

namespace IGlobalist.Cms.DataAccess
{
    /// <summary>
    /// Config service
    /// </summary>
    public class ServiceConfig
    {
        static private object _synRoot = new Object();
        static private ServiceConfig _instance;

        private IDaoManager _daoManager = null;

        private ServiceConfig() { }
        /// <summary>
        /// Get instance service config
        /// </summary>
        /// <returns>ServiceConfig</returns>
        static public ServiceConfig GetInstance()
        {
            if (_instance == null)
            {
                lock (_synRoot)
                {
                    if (_instance == null)
                    {
                        try
                        {
                            DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
                            ConfigureHandler handler = new ConfigureHandler(ServiceConfig.Reset);
                            builder.ConfigureAndWatch(handler);
                            _instance = new ServiceConfig();
                            _instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance("SqlMapDao");
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
             
                    }
                }
            }
            return _instance;
        }

       
        /// <summary>
        /// Resert ServiceConfig
        /// </summary>
        /// <param name="obj">ServiceConfig object</param>
        static public void Reset(object obj)
        {
            _instance = null;
        }

        public IDaoManager DaoManager
        {
            get
            {
                return _daoManager;
            }
        }

    }
}
